import 'package:netease_music/utils/dio_client.dart';

class RealApi {
  // 获取歌曲url
  static Future<Map<String, dynamic>> getSongUrl(int id) async {
    final response = await DioUtil().get('/song/url', queryParams: {'id': id});
    if (response.statusCode == 200) {
      return response.data as Map<String, dynamic>; // 明确转换类型
    } else {
      throw Exception('Failed to load data: ${response.statusCode}');
    }
  }

  // 获取搜索结果 关键词 分页 数量 类型 1: 单曲, 10: 专辑, 100: 歌手, 1000: 歌单, 1002: 用户, 1004: MV, 1006: 歌词, 1009: 电台, 1014: 视频, 1018:综合, 2000:声音(搜索声音返回字段格式会不一样)
  static Future<Map<String, dynamic>> getCloudSearch(String keywords,
      {int offset = 0, int limit = 20, int type = 1}) async {
    final response = await DioUtil().get('/cloudsearch', queryParams: {
      'keywords': keywords,
      'offset': offset,
      'limit': limit,
      'type': type,
    });
    if (response.statusCode == 200) {
      return response.data as Map<String, dynamic>; // 明确转换类型
    } else {
      throw Exception('Failed to load data: ${response.statusCode}');
    }
  }

  // 歌单详情
  static Future<Map<String, dynamic>> getPlayListDetail(int id) async {
    final response =
        await DioUtil().get('/playlist/detail', queryParams: {'id': id});
    if (response.statusCode == 200) {
      return response.data as Map<String, dynamic>; // 明确转换类型
    } else {
      throw Exception('Failed to load data: ${response.statusCode}');
    }
  }

  // 获取歌词
  static Future<Map<String, dynamic>> getLyric(int id) async {
    final response = await DioUtil().get('/lyric', queryParams: {'id': id});
    if (response.statusCode == 200) {
      return response.data as Map<String, dynamic>; // 明确转换类型
    } else {
      throw Exception('Failed to load data: ${response.statusCode}');
    }
  }
}
